<?php 
class indexControl extends control{
	function index(){
		if(isset($_SESSION['user'])){
			unset($_SESSION['user']);
		}
		$this->display();
	}
	function admin(){
		$this->display();
	}
	function right(){
		$db = new mysql('user');
		$db->select();
		$totalnum = $db->affected_rows();
		$page = new page($totalnum,5,7);
		$arr = $page->page_list_current;
		$user = $db->limit($page->limit)->select();
		$pagetotal = $page->total_page;
		$this->assign('page',$arr);
		$this->assign('users', $user);
		$this->display();
	}
	function code(){
		$code=new code(80,30);
		$code->show();
	}
	function login(){
		$db=new mysql("user");
		$rows=$db->select();
		$arr=array();
		if(strtoupper($_SESSION['code'])!=strtoupper($_POST['code'])){
			$arr['state']=1;
			$arr['msg']="验证码错误！";
			echo json_encode($arr);
			exit;
		}
		$u=false;
		$p=false;
		foreach($rows as $v){
			if($v['uname']==$_POST['user']){
				$u=true;
				if($v['pwd']==md5($_POST['pwd'])){
					$p=true;
				}
			}
		}
		if(!$u){
			$arr['state']=2;
			$arr['msg']="用户名不存在！";
			echo json_encode($arr);
			exit;
		}
		if(!$p){
			$arr['state']=3;
			$arr['msg']="密码错误！";
			echo json_encode($arr);
			exit;
		}
		$arr['state']=4;
		$_SESSION['user']=$_POST['user'];
		echo json_encode($arr);
	}
}
?>